package cn.wubo.vrr.help.controller;

import cn.wubo.vrr.help.entity.Person;
import cn.wubo.vrr.help.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/person")
public class PersonController {

    @Autowired
    PersonService personService;

    @RequestMapping(value = "/all", method = RequestMethod.GET)
    @ResponseBody
    public List<Person> findAll() {
        return personService.findAll();
    }

    @RequestMapping(value = "/save", method = RequestMethod.PUT)
    @ResponseBody
    public Person save(@RequestParam(value = "name", required = true) String name,
                       @RequestParam(value = "employeeId", required = true) String employeeId,
                       @RequestParam(value = "phone", required = true) String phone,
                       @RequestParam(value = "email", required = true) String email) {
        Person p = new Person();
        p.setName(name);
        p.setEmployeeId(employeeId);
        p.setPhone(phone);
        p.setEmail(email);
        return personService.save(p);
    }

    @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
    @ResponseBody
    public Integer delete(@PathVariable(value = "id", required = true) Integer id) {
        return personService.deleteById(id);
    }
}
